﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TRPOP.Controls
{
    /// <summary>
    /// TextBox
    /// </summary>
    public class TextBox : System.Web.UI.WebControls.TextBox
    {
        private EnumValueType m_enmValueType = EnumValueType.String;
        /// <summary>
        /// 
        /// </summary>
        public EnumValueType ControlValueType
        {
            set { m_enmValueType = value; }
            get { return m_enmValueType; }
        }
        /// <summary>
        /// 
        /// </summary>
        public TextBox()
        {

        }
        /// <summary>
        /// 删除Text的首尾空格
        /// </summary>
        public string TextTrim
        {
            get { return this.Text.Trim(); }
        }

        /// <summary>
        /// 替换sql语句中的有问题符号
        /// </summary>
        public string TextFilterSQL
        {
            get
            {
                return this.TextTrim.Replace("'", "''");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            //样式class
            if (this.CssClass == "")
            {
                this.Attributes.Add("class", "txtBlur");
                this.Attributes.Add("onfocus", "this.className=\"control_focus\"");
                this.Attributes.Add("onblur", "this.className=\"control_blur\"");
            }
            //else
            //{
            //    this.Attributes.Add("class", this.CssClass);
            //    this.Attributes.Add("onfocus", "this.className=\"control_focus\"");
            //    this.Attributes.Add("onblur", "this.className=\""+this.CssClass+"\"");
            //}
            //Width
            if (this.Width.Value == 0)
            {
                switch (m_enmValueType)
                {
                    //日期型 1900-01-01
                    case EnumValueType.Date:
                        this.Width = new System.Web.UI.WebControls.Unit(63);
                        break;
                    //字符串型
                    case EnumValueType.String:
                        this.Width = new System.Web.UI.WebControls.Unit(346);
                        break;
                    //小数
                    case EnumValueType.Decimal:
                        this.Width = new System.Web.UI.WebControls.Unit(50);
                        break;
                    //整型数值
                    case EnumValueType.Int:
                        this.Width = new System.Web.UI.WebControls.Unit(40);
                        break;
                    //搜索框
                    case EnumValueType.Search:
                        this.Width = new System.Web.UI.WebControls.Unit(100);
                        break;
                    //邮编
                    case EnumValueType.PostalCode:
                        this.Width = new System.Web.UI.WebControls.Unit(45);
                        break;
                    //电话
                    case EnumValueType.Tel:
                        this.Width = new System.Web.UI.WebControls.Unit(80);
                        break;
                    default:
                        break;
                }
            }
            base.Render(writer);
        }

    }
}
